package com.ruoyi.project.order.in.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.order.in.domain.CheckIn;
import com.ruoyi.project.order.in.service.ICheckInService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 入住退房登记Controller
 * 
 * @author yyj
 * @date 2021-05-13
 */
@Controller
@RequestMapping("/order/in")
public class CheckInController extends BaseController
{
    private String prefix = "order/in";

    @Autowired
    private ICheckInService checkInService;

    @RequiresPermissions("order:in:view")
    @GetMapping()
    public String in()
    {
        return prefix + "/in";
    }

    /**
     * 查询入住退房登记列表
     */
    @RequiresPermissions("order:in:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CheckIn checkIn)
    {
        startPage();
        List<CheckIn> list = checkInService.selectCheckInList(checkIn);
        return getDataTable(list);
    }

    /**
     * 导出入住退房登记列表
     */
    @RequiresPermissions("order:in:export")
    @Log(title = "入住退房登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CheckIn checkIn)
    {
        List<CheckIn> list = checkInService.selectCheckInList(checkIn);
        ExcelUtil<CheckIn> util = new ExcelUtil<CheckIn>(CheckIn.class);
        return util.exportExcel(list, "in");
    }

    /**
     * 新增入住退房登记
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入住退房登记
     */
    @RequiresPermissions("order:in:add")
    @Log(title = "入住退房登记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CheckIn checkIn)
    {
        return toAjax(checkInService.insertCheckIn(checkIn));
    }

    /**
     * 修改入住退房登记
     */
    @GetMapping("/edit/{checkInId}")
    public String edit(@PathVariable("checkInId") Long checkInId, ModelMap mmap)
    {
        CheckIn checkIn = checkInService.selectCheckInById(checkInId);
        mmap.put("checkIn", checkIn);
        return prefix + "/edit";
    }

    /**
     * 修改保存入住退房登记
     */
    @RequiresPermissions("order:in:edit")
    @Log(title = "入住退房登记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CheckIn checkIn)
    {
        return toAjax(checkInService.updateCheckIn(checkIn));
    }

    /**
     * 删除入住退房登记
     */
    @RequiresPermissions("order:in:remove")
    @Log(title = "入住退房登记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(checkInService.deleteCheckInByIds(ids));
    }
}
